#include "Score.h"
#include "Input/InputManager.h"
#include "Assets/FontManager.h"
#include "GlobalVariables.h"

Score::Score()
	: Object(),
	m_pText(nullptr)
{
}

Score::~Score()
{
}

void Score::Initialize()
{
	star::FontManager::GetInstance()->LoadFont(_T("PixelMotion.ttf"),_T("PixelMotion"), 40);
	
	m_pText = new star::TextComponent(_T("PixelMotion.ttf"),_T("Score"), 40);
	m_pText->SetText(_T("0 0 0 0 0 0 0 0 0 0"));
	AddComponent(m_pText);
	
}

void Score::Update(const star::Context& context)
{
	//8 numbers in total - 0's in front
	tstringstream scoreStream;
	uint64 score = GlobalVariables::GetInstance()->GetScore();
	scoreStream << score;

	tstring scoreStr = scoreStream.str();
	int size = scoreStr.length();

	tstringstream prequelScoreString;
	prequelScoreString << _T("Score:");
	for(int i = 0; i < SCORESIZE - size; ++i)
	{
		prequelScoreString <<_T("0");
	}
	tstring temp = prequelScoreString.str();

	GetComponent<star::TextComponent>()->SetText(temp + scoreStr);
}